package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.domain.DataResult;
import com.dongdongshop.em.DataResultEnum;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.TbContentCategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("TbContentCategoryController")
@Controller
public class TbContentCategoryController {


    @Reference
    private TbContentCategoryService categoryService;


    @RequestMapping("ToShow")
    public String toShow(){
        return "admin/content_category";
    }

    @ResponseBody
    @RequestMapping("getContentCatgory")
    public DataResult getContentCatgory(){
        List<TbContentCategory> selectss = categoryService.selectss();
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(selectss);
    }

    @RequestMapping("deleteContent")
    @ResponseBody
    public DataResult deleteContent(@RequestParam("ids[]") Long[] ids){
        categoryService.deleteByid(ids);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS);
    }

    @RequestMapping("toaddcategory")
    @ResponseBody
    public DataResult toaddcategory(TbContentCategory category){
        Boolean insertinto = categoryService.insertinto(category);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(insertinto);
    }

    @ResponseBody
    @RequestMapping("toupdata")
    public DataResult toupdata(Long id){
        TbContentCategory tbContentCategory =  categoryService.toupdata(id);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(tbContentCategory);
    }

    @RequestMapping("toupdatas")
    @ResponseBody
    public DataResult toupdatas(TbContentCategory category){
        Boolean updatas = categoryService.updatas(category);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(updatas);
    }
}
